package eitwitter.storage;

import java.util.EnumMap;

/**
 * Classe permettant de contenir la matrice des couts
 * @author AH & PJ
 */
public class CostsMatrix {
	
	/** Instance de la classe */
	private static CostsMatrix instance;
	
	/** Variable contenant la matrice des couts (vraie categorie, categorie trouvee) */
	private EnumMap<Category, EnumMap<Category, Integer>> costs;

	/**
	 * Matrice de confusion initialisee 
	 */
	private CostsMatrix() {
	
		// Initialisation de l'objet qui stocke
		costs = new EnumMap<Category, EnumMap<Category, Integer>>(Category.class);
		
		// Initilisation des objets stockes
		costs.put(Category.POSITIVE, new EnumMap<Category, Integer>(Category.class));
		costs.put(Category.NEGATIVE, new EnumMap<Category, Integer>(Category.class));
		costs.put(Category.NEUTRAL, new EnumMap<Category, Integer>(Category.class));
		costs.put(Category.IRRELEVANT, new EnumMap<Category, Integer>(Category.class));
		
		costs.get(Category.POSITIVE).put(Category.POSITIVE, 0);
		costs.get(Category.POSITIVE).put(Category.NEGATIVE, 2);
		costs.get(Category.POSITIVE).put(Category.NEUTRAL, 3);
		costs.get(Category.POSITIVE).put(Category.IRRELEVANT, 3);
		
		costs.get(Category.NEGATIVE).put(Category.POSITIVE, 2);
		costs.get(Category.NEGATIVE).put(Category.NEGATIVE, 0);
		costs.get(Category.NEGATIVE).put(Category.NEUTRAL, 3);
		costs.get(Category.NEGATIVE).put(Category.IRRELEVANT, 3);
		
		costs.get(Category.NEUTRAL).put(Category.POSITIVE, 4);
		costs.get(Category.NEUTRAL).put(Category.NEGATIVE, 4);
		costs.get(Category.NEUTRAL).put(Category.NEUTRAL, 0);
		costs.get(Category.NEUTRAL).put(Category.IRRELEVANT, 1);
		
		costs.get(Category.IRRELEVANT).put(Category.POSITIVE, 4);
		costs.get(Category.IRRELEVANT).put(Category.NEGATIVE, 4);
		costs.get(Category.IRRELEVANT).put(Category.NEUTRAL, 1);
		costs.get(Category.IRRELEVANT).put(Category.IRRELEVANT, 0);
	}
	
	/**
	 * Retourne le cout lorsque pour le couple {categorie reelle, categorie trouvee }
	 * @param real			Categorie reelle du tweet
	 * @param identified	Categorie identifiee
	 * @return Cout pour le couple de categories
	 */
	public int getCost(Category real, Category identified){
		if(costs.get(real) != null){
			Integer cost = costs.get(real).get(identified);
			if(cost != null){
				return cost;
			}
		}
		return 0;
	}
	
	/**
	 * Cree ou retourne le singleton
	 * @return Retourne la reference vers le singleton
	 */
	public static CostsMatrix getInstance(){
		
		// Si l'initialisation n'a pas ete fait, on la fait
		if(instance == null){
			instance = new CostsMatrix();
		}
		return instance;
	}
	
}
